package com.example.springworkadmin.dao;

import com.example.springworkadmin.entity.UserAccount;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository

public interface UserAccountDao {

    @Select("select * from user where account=#{id}")
    UserAccount getById(@Param("id")String id);

    @Select("select count(*) from user where authority='ADMIN' and account like concat('%',#{key},'%')")
    Integer count(@Param("key") String key);

    @Select("select * from user where authority='ADMIN' and account like concat('%',#{key},'%') order by account desc limit #{start},#{size}")
    List<UserAccount> get(@Param("start") Integer start, @Param("size") Integer limit, @Param("key") String key);

    @Insert("insert into user(account,password,authority) values(#{o.account},#{o.password},'ADMIN')")
    Integer add(@Param("o") UserAccount userAccount);

    @Update("update user set password=#{o.password} where account=#{o.account}")
    Integer update(@Param("o") UserAccount userAccount);

    @Delete("delete from user where account=#{id} and authority='ADMIN'")
    Integer delete(@Param("id") String id);
}
